package com.salmon.security.app.social.impl;

import com.salmon.security.app.handler.SalmonAuthenticationFailureHandler;
import com.salmon.security.core.social.SocialAuthenticationFilterPostProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.social.security.SocialAuthenticationFilter;
import org.springframework.stereotype.Component;

/**
 * 后处理器在APP环境中需要设置第三方登陆的时候用code去换token的时候的成功处理器
 * 在浏览器模式下不需要实现SocialAuthenticationFilterPostProcessor
 * 默认的方式是跳转页面，在APP环境中无法使用，所以需要实现SocialAuthenticationFilterPostProcessor来自定义的成功处理器
 */
@Component
public class AppSocialAuthenticationFilterPostProcessor implements SocialAuthenticationFilterPostProcessor {

    @Autowired
    private AuthenticationSuccessHandler salmonAuthenticationSuccessHandler;

    @Autowired
    private SalmonAuthenticationFailureHandler salmonAuthenticationFailureHandler;

    @Override
    public void process(SocialAuthenticationFilter socialAuthenticationFilter) {
        socialAuthenticationFilter.setAuthenticationSuccessHandler(salmonAuthenticationSuccessHandler);
        socialAuthenticationFilter.setAuthenticationFailureHandler(salmonAuthenticationFailureHandler);
    }
}
